package com.hmall.user.controller;

import com.hmall.user.pojo.Address;
import com.hmall.user.pojo.User;
import com.hmall.user.service.UserService;
import com.hmall.user.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {
    //注入service层
    @Autowired
    private UserService userService;

    /**
     * 根据用户id查询用户的地址
     */
    @GetMapping("/address/uid")
    public List<Address> findAddressByUid() {
        Long userId = ThreadLocalUtil.getUserId();
        return userService.findAddressByUid(userId);
    }

    @GetMapping("/address/{addressId}")
    public Address findAddresses(@PathVariable("addressId") Long id){
       return userService.findAddresses(id);
    }


    @GetMapping("/user/{userId}")
    public User findUserById(@PathVariable("userId") Long userId){
        return userService.findUserById(userId);
    }

    @RequestMapping("/user/{money}/{id}")
    public void updateUser(@PathVariable("money") Long money,
                           @PathVariable("id") Long id){
        userService.updateUser(money,id);
    }
}
